#pragma once
#include <windows.h>
#include <windowsx.h>
#include <atlbase.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9anim.h>

#ifndef SAFE_DELETE
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
#endif    
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
#endif    
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
#endif
#ifndef V
#define V(x)           { hr = x; }
#endif

/**
 * \class CMeshHierarchy
 * \brief This class defines a number of callbacks required by the D3DXLoadMeshHierarchyFromX function.
 * The required functions are defined by the abstract interface class: ID3DXAllocateHierarchy
 * \author Keith Ditchburn \date 17 July 2005
*/
class CMeshHierarchy : public ID3DXAllocateHierarchy
{
public:	
    // callback to create a D3DXFRAME extended object and initialize it
    STDMETHOD( CreateFrame )( THIS_ LPCSTR Name, LPD3DXFRAME *ppNewFrame );

    // callback to create a D3DXMESHCONTAINER extended object and initialize it
    STDMETHOD( CreateMeshContainer )( THIS_ LPCSTR Name, CONST D3DXMESHDATA * pMeshData, 
                            CONST D3DXMATERIAL * pMaterials, CONST D3DXEFFECTINSTANCE * pEffectInstances,
                            DWORD NumMaterials, CONST DWORD * pAdjacency, LPD3DXSKININFO pSkinInfo, 
                            LPD3DXMESHCONTAINER * ppNewMeshContainer );

    // callback to release a D3DXFRAME extended object
    STDMETHOD( DestroyFrame )( THIS_ LPD3DXFRAME pFrameToFree );

    // callback to release a D3DXMESHCONTAINER extended object
    STDMETHOD( DestroyMeshContainer )( THIS_ LPD3DXMESHCONTAINER pMeshContainerToFree );
};